package com.usvisatrack.core.factories;

import java.util.Date;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.criterion.Restrictions;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.usvisatrack.core.common.Factory;
import com.usvisatrack.core.dao.model.CheckeeVisa;
import com.usvisatrack.core.dao.model.SocialMedia;
import com.usvisatrack.core.dao.model.SocialMediaLog;
import com.usvisatrack.core.dao.model.Visa;
import com.usvisatrack.core.dao.model.VisaClass;
import com.usvisatrack.core.dao.model.VisaStatusLog;

/**
 * Item Data Factory
 * 
 * @author YuCheng Hu
 *
 */
public class SocialMediaFactory extends Factory {
	private static Logger logger = LoggerFactory.getLogger(SocialMediaFactory.class);

	private static final int LISTING_PAGE_SIZE = 20;
	public static final int DEFAULT_AUTH_EXPIRATION = 10;

	/**
	 * Get VISA
	 * 
	 * @param id
	 * @return
	 */
	public static SocialMedia get(Long id) {
		logger.debug("Get Visa OBJ by ID - [{}]", id);
		Factory.beginTransaction();
		SocialMedia socialMedia = null;
		try {
			socialMedia = Factory.get(SocialMedia.class, id);
			Factory.commitTransaction();
		} catch (Exception ex) {
			socialMedia = null;
			logger.error("Get Visa by item ID error", ex);
		} finally {
			Factory.commitTransaction();
		}

		return socialMedia;
	}

	/**
	 * Get SocialMedia Object by SocialMedia Name
	 * 
	 * @param socialMediaName
	 * @return
	 */
	public static SocialMedia get(String socialMediaName) {
		logger.debug("Get SocialMedia OBJ by Name - [{}]", socialMediaName);
		SocialMedia socialMedia = null;
		Factory.beginTransaction();

		try {
			Criteria criteria = Factory.createCriteria(SocialMedia.class);
			criteria.add(Restrictions.eq("name", socialMediaName));
			socialMedia = (SocialMedia) criteria.uniqueResult();
		} catch (Exception ex) {
			socialMedia = null;
			logger.error("Get Visa by item ID error", ex);
		} finally {
			Factory.commitTransaction();
		}
		return socialMedia;
	}

	public static void save(SocialMediaLog socialMediaLog) {
		try {
			Factory.beginTransaction();
			Factory.saveOrUpdate(socialMediaLog);
			Factory.commitTransaction();
		} catch (Exception ex) {
			logger.error("Save CheckeeVisa OBJ ERROR", ex);
			Factory.rollbackTransaction();
		}
	}

}